<template>
  <div>
    <!-- 面包屑导航区 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>举报管理</el-breadcrumb-item>
      <el-breadcrumb-item>举报列表</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card>
      <el-row :gutter="20">
        <el-col :span="8">
          <el-input
            placeholder="请输入被举报i、举报id或内容（模糊搜索）"
            v-model="queryInfo.query"
          >
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="handleQueryOrder()"
            ></el-button> </el-input
        ></el-col>
      </el-row>

      <el-table :data="reList" border style="width: 100%">
        <el-table-column type="index"> </el-table-column>
        <el-table-column prop="id" label="id"> </el-table-column>
        <el-table-column prop="reporter_id" label="举报者id"> </el-table-column>
        <el-table-column prop="violator_id" label="被举报者id">
        </el-table-column>
        <el-table-column prop="content" label="举报内容"> </el-table-column>
        <el-table-column prop="create_time" label="创建时间">
          <template slot-scope="scope">
            {{ scope.row.create_time | dateFormat }}
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页区域 -->
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[10, 20, 50]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      reList: [],
      total: 0
    }
  },
  created() {
    this.getReporterList()
  },
  methods: {
    async getReporterList() {
      const { data: res } = await this.$http.get('/reporter/getAll', {
        params: this.queryInfo
      })

      if (res.code !== 200) {
        this.$message.error('获取举报列表失败')
        return
      }

      this.reList = JSON.parse(res.msg).list
      this.total = JSON.parse(res.msg).total
      this.$message.success('获取举报列表成功')
    },
    handleQueryOrder() {
      this.queryInfo.pagenum = 1
      this.getReporterList()
    },
    handleSizeChange(newSize) {
      this.queryInfo.pagesize = newSize
      this.getReporterList()
    },

    handleCurrentChange(newPage) {
      this.queryInfo.pagenum = newPage
      this.getReporterList()
    }
  }
}
</script>

<style lang="less" scoped></style>
